package com.listeningframework.boot.autoconfigure.security.userdetails;

import org.apache.commons.lang3.StringUtils;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;

import java.util.Collection;

/**
 * Created by lixining on 2017/7/26.
 */
public class SecurityUserDetails implements UserDetails {
    /**  */
    private static final long serialVersionUID = -5769319137904785295L;
    /**
     * 权限资源
     */
    private Collection<? extends GrantedAuthority> authorities;
    /**
     * 客户菜单
     */
    private SecurityMenus securityMenus;
    /**
     * 邮件
     */
    private String email;
    /**
     * 是否可用
     */
    private boolean enabled;
    /**
     * 手机
     */
    private String mobile;
    /**
     * 密码
     */
    private String password;
    /**
     * 真实姓名
     */
    private String realName;
    /**
     * 用户名
     */
    private String username;
    /**
     * 用户ID
     */
    private String userId;

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    public String getEmail() {
        return email;
    }

    public String getMobile() {
        return mobile;
    }

    @Override
    public String getPassword() {
        return password;
    }

    public String getRealName() {
        return realName;
    }

    @Override
    public String getUsername() {
        return username;
    }

    @Override
    public boolean isAccountNonExpired() {
        return enabled;
    }

    @Override
    public boolean isAccountNonLocked() {
        return enabled;
    }

    @Override
    public boolean isCredentialsNonExpired() {
        return enabled;
    }

    @Override
    public boolean isEnabled() {
        return enabled;
    }

    public void setAuthorities(Collection<? extends GrantedAuthority> authorities) {
        this.authorities = authorities;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public void setEnabled(boolean enabled) {
        this.enabled = enabled;
    }

    public void setMobile(String mobile) {
        this.mobile = mobile;
    }

    public void setPassword(String password) {
        this.password = password;
    }

    public void setRealName(String realName) {
        this.realName = realName;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public SecurityMenus getSecurityMenus() {
        return securityMenus;
    }

    public void setSecurityMenus(SecurityMenus securityMenus) {
        this.securityMenus = securityMenus;
    }

    /**
     * @see java.lang.Object#hashCode()
     */
    @Override
    public int hashCode() {
        return username.hashCode();
    }

    /**
     * @see java.lang.Object#equals(java.lang.Object)
     */
    @Override
    public boolean equals(Object obj) {
        if (!(obj instanceof SecurityUserDetails)) {
            return false;
        }
        SecurityUserDetails details = (SecurityUserDetails) obj;
        return StringUtils.equals(details.getUsername(), username);
    }

}
